package com.longge;

public class TemperatureTrend {

    public int temperatureTrend(int[] temperatureA, int[] temperatureB) {

        int[] aRes = new int[temperatureA.length - 1];
        int[] bRes = new int[temperatureB.length - 1];
        fillRes(aRes, temperatureA);
        fillRes(bRes, temperatureB);
        int res = 0;
        int count = 0;
        for (int i = 0; i < aRes.length; i++) {
            if (aRes[i] == bRes[i]) count++;
            else count = 0;
            res = Math.max(count,res);
        }
        return res;

    }

    private void fillRes(int[] res, int[] temperature) {
        for (int i = 0; i < temperature.length - 1; i++) {
            if (temperature[i + 1] > temperature[i]) {
                res[i] = 1;
            } else if (temperature[i + 1] == temperature[i]) {
                res[i] = 0;
            } else {
                res[i] = -1;
            }
        }

    }
}
